#!/usr/bin/env python
"""A ping command for RyCE.
"""
__plugin_name__ = 'ping'
#-IMPORTS----------------------------------------------------------------------
import os
import cmdobj
#-CLASSES----------------------------------------------------------------------
class ping(cmdobj.CmdObject):
    """Command extension that executes a ping.
    """
    def __init__(self, p_params):
        self.__ip = p_params[cmdobj.IP]
        self.__cmp_tokens = []
        temp_args = []
        if os.name == 'posix':
            self.__cmp_tokens.append('100% packet loss')
            self.__cmp_tokens.append('unknown host')
            temp_args.append('-c')
            temp_args.append('1')
            temp_args.append('%s' % self.__ip)
            cmdobj.CmdObject.__init__(self,
                                      p_os = 'posix',
                                      p_cmd = 'ping',
                                      p_args = temp_args,
                                      p_name = __plugin_name__)
        elif (os.name == 'nt') or (os.name == 'dos'):
            self.__cmp_tokens.append('100% loss')
            self.__cmp_tokens.append('Ping request could not find host')
            temp_args.append('-n')
            temp_args.append('1')
            temp_args.append('%s'%self.__ip)
            cmdobj.CmdObject.__init__(self,
                                      p_os = 'nt',
                                      p_cmd = 'c:\\windows\\system32\\ping.exe',
                                      p_args = temp_args,
                                      p_name = __plugin_name__)
